/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package prototype.santana;


import java.awt.Frame;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author Eric
 */
public class MedicationDialog extends javax.swing.JDialog {

    DefaultTableModel recordingTable;
    /**
     * Creates new form MedicationDialog
     */
    public MedicationDialog(Frame parent, boolean modal, TableModel recordingTable) {
        super(parent, modal);
        initComponents();
        setLocation(
                (getToolkit().getScreenSize().width-getWidth())/2,
                (getToolkit().getScreenSize().height-getHeight())/2);
        
      medicationNameLabel.setText(
              (String)((SimulationGUI)parent).
              getMarTable().getModel().
              getValueAt(((SimulationGUI)parent).getMarTable().getSelectedRow(), 0));
      
      setVisible(true);
      
      this.recordingTable = (DefaultTableModel) recordingTable;
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        giveMedicationConfirmButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        medicationNameLabel = new javax.swing.JLabel();
        amountTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        unitsTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        notesTextPane = new javax.swing.JTextPane();
        cancelButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        followUpTextField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        initialsTextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        giveMedicationConfirmButton.setText("Give Medication");
        giveMedicationConfirmButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                giveMedicationConfirmButtonActionPerformed(evt);
            }
        });

        jLabel1.setText("Amount");

        medicationNameLabel.setText("Medication Name");

        amountTextField.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        amountTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                amountTextFieldActionPerformed(evt);
            }
        });
        amountTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                amountTextFieldKeyTyped(evt);
            }
        });

        jLabel3.setText("Units");

        unitsTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                unitsTextFieldActionPerformed(evt);
            }
        });

        jLabel4.setText("Notes");

        jScrollPane1.setViewportView(notesTextPane);

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        jLabel2.setText("Follow up");

        jLabel5.setText("Initials");

        jLabel6.setText("Medication");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(139, 139, 139)
                        .addComponent(jLabel1)
                        .addGap(46, 46, 46)
                        .addComponent(jLabel3)
                        .addGap(133, 133, 133)
                        .addComponent(jLabel2)
                        .addGap(83, 83, 83)
                        .addComponent(jLabel5))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(medicationNameLabel)
                        .addGap(109, 109, 109)
                        .addComponent(amountTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23)
                        .addComponent(unitsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(36, 36, 36)
                        .addComponent(followUpTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(initialsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(133, 133, 133)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(giveMedicationConfirmButton)
                            .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(10, 10, 10))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel5))))
                .addGap(5, 5, 5)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(amountTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(unitsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(followUpTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(initialsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(medicationNameLabel))
                .addGap(47, 47, 47)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(6, 6, 6)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(giveMedicationConfirmButton)
                        .addGap(105, 105, 105)
                        .addComponent(cancelButton))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void giveMedicationConfirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_giveMedicationConfirmButtonActionPerformed
        // TODO add your handling code here:
       DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
       DateFormat dayFormat = new SimpleDateFormat("HH:mma");

       recordingTable.addRow(
                new String[]{
                    dateFormat.format(Calendar.getInstance(TimeZone.getDefault()).getTime()),
                    dayFormat.format(Calendar.getInstance(TimeZone.getDefault()).getTime()),
"Medication Given: "+medicationNameLabel.getText()+ " Dose:"+amountTextField.getText()+" "+unitsTextField.getText()+" Notes:\n"+notesTextPane.getText(),
                followUpTextField.getText(),
                initialsTextField.getText()});
        this.dispose();
    }//GEN-LAST:event_giveMedicationConfirmButtonActionPerformed

    private void unitsTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unitsTextFieldActionPerformed

    }//GEN-LAST:event_unitsTextFieldActionPerformed

    private void amountTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_amountTextFieldActionPerformed

        
    }//GEN-LAST:event_amountTextFieldActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
       dispose();
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void amountTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_amountTextFieldKeyTyped
        // TODO add your handling code here:
        if(evt.getKeyChar()>=java.awt.event.KeyEvent.VK_0 && 
           evt.getKeyChar()<=java.awt.event.KeyEvent.VK_9 &&
           amountTextField.isFocusOwner())
            amountTextField.setText(amountTextField.getText()+evt.getKeyChar());
        else if(evt.getKeyChar()!=java.awt.event.KeyEvent.VK_BACK_SPACE)
            amountTextField.setText(amountTextField.getText().substring(0,amountTextField.getText().length()-1 ));
    }//GEN-LAST:event_amountTextFieldKeyTyped

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        
//        /*
//         * Set the Nimbus look and feel
//         */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /*
//         * If Nimbus (introduced in Java SE 6) is not available, stay with the
//         * default look and feel. For details see
//         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(MedicationDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(MedicationDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(MedicationDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(MedicationDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /*
//         * Create and display the dialog
//         */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
////                MedicationDialog dialog = new MedicationDialog(new javax.swing.JFrame(), true);
////                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
////
////                    @Override
////                    public void windowClosing(java.awt.event.WindowEvent e) {
////                        System.exit(0);
////                    }
////                });
////                dialog.setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField amountTextField;
    private javax.swing.JButton cancelButton;
    private javax.swing.JTextField followUpTextField;
    private javax.swing.JButton giveMedicationConfirmButton;
    private javax.swing.JTextField initialsTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel medicationNameLabel;
    private javax.swing.JTextPane notesTextPane;
    private javax.swing.JTextField unitsTextField;
    // End of variables declaration//GEN-END:variables
}
